<template>
  <div>
    <el-dialog :title="dialogParam.title" :visible="dialogParam.dialogVisible" width="30%">
      <el-row>
        <el-col>
          <label>角色名称</label>
          <el-input
            v-model="dialogParam.role.roleName"
            size="medium"
            placeholder="请输入角色名称"
          >
          </el-input>
        </el-col>
      </el-row>
      <el-row>
        <el-col>
          <label>角色编码</label>
          <el-input
            v-model="dialogParam.role.roleCode"
            size="medium"
            placeholder="请输入角色编码"
          >
          </el-input>
        </el-col>
      </el-row>
      <el-row>
        <el-col>
          <label>角色描述</label>
          <el-input
            v-model="dialogParam.role.description"
            size="medium"
            placeholder="请输入角色描述"
          >
          </el-input>
        </el-col>
      </el-row>

      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogParam.dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="submitRole"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { insertRole, updateRole } from "@/api/role/role";

export default {
  name: "",
  components: {},
  props: ['dialogParam','getAllRoles'],
  data() {
    return {};
  },
  computed: {},
  watch: {},
  methods: {
    submitRole() {
      if (this.dialogParam.state == "insert") {
        insertRole(this.dialogParam.role).then((res) => {
          if (res.data) {
            this.$message.success("添加成功");
          } else {
            this.$message.error("添加失败");
          }
          this.getAllRoles();
        });
      } else if (this.dialogParam.state == "update") {
        updateRole(this.dialogParam.role).then((res) => {
          if (res.data) {
            this.$message.success("修改成功");
          } else {
            this.$message.error("修改失败");
          }
          this.getAllRoles();
        });
      }
      this.dialogParam.dialogVisible=false;
    },
  },
  created() {},
  mounted() {},
  beforeCreate() {},
  beforeMount() {},
  beforeUpdate() {},
  updated() {},
  beforeDestroy() {},
  destroyed() {},
  activated() {},
};
</script>
<style scoped>
</style>